package com.zlop.common.utils;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * 字段验证
 *
 * @author  曾令鹏
 * @since   jdk1.8
 * @version 2018年4月9日 曾令鹏
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ValidateUtil {

	/**
	 * 参数验证
	 * @param result
	 */
	public static void checkArgument(BindingResult result) {
		if (result.hasErrors()) {
			ObjectError objectError = result.getAllErrors().get(0);
			throw new IllegalArgumentException(objectError.getDefaultMessage());
		}
	}
}